<?php

namespace App\Admin\Controllers;

use App\Admin\Repositories\Collage;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Controllers\AdminController;

class CollageController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Collage(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('cover')->display(function ($name) {
                return "<img src='http://house.hhnwxs.cn/$name' width='80px' height='60px' />";
            });
            $grid->column('title');
            $grid->column('houses_name');
            $grid->column('houses_address');
            $grid->column('start_time');
            $grid->column('end_time');
            $grid->column('number','入团人数');
            $grid->column('collage_number','开团总人数');
            $grid->column('desc');
            $grid->column('intermediary_id');
            $grid->column('status','是否开团')->switch();
//            $grid->column('created_at');
//            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Collage(), function (Show $show) {
            $show->field('id');
            $show->field('cover');
            $show->field('title');
            $show->field('houses_name');
            $show->field('houses_address');
            $show->field('start_time');
            $show->field('end_time');
            $show->field('number');
            $show->field('collage_number');
            $show->field('desc');
            $show->field('intermediary_id');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Collage(), function (Form $form) {
            $form->display('id');
            $form->image('cover')->disk("oss")->uniqueName();
            $form->text('title');
            $form->text('houses_name');
            $form->text('houses_address');
            $form->datetime('start_time');
            $form->datetime('end_time');
            $form->number('collage_number','开团总人数');
            $form->text('desc');
            $form->number('intermediary_id');
            $form->switch('status','是否开启');

        });
    }
}
